package com.zone.demo.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zone.demo.dto.Account;
import com.zone.demo.dto.User;
import com.zone.demo.service.UserService;
import com.zone.demo.util.JsonResult;
import com.zone.demo.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created with IntelliJ IDEA.
 * User: SJP
 * Date: 2021/7/8
 * Time: 16:25
 * Description: No Description
 * @author SJP
 */
@RestController
public class UserController {

   private final UserService userService;


    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
    * Description  通过用户姓名获取账户信息
    * @author shao
    * @param name:
    * @date 2021/7/9 15:31
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping(value = "/getAmountByName")
    public JsonResult getAmountByName(String name) {
       Account account = this.userService.getAmountByName(name);
       return new JsonResult(ResultCode.SUCCESS, account);
    }
    /**
    * Description 创建用户表单
     *
    * @author shao
    * @param :
    * @date 2021/7/9 15:31
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping(value = "/createTableUser")
    public JsonResult createTableUser() {
        this.userService.createTableUser();
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
    * Description 添加记录到用户表单
    * @author shao
    * @param current:
    * @param limit:
    * @date 2021/7/9 15:31
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping(value = "/insertDataToUser")
    public JsonResult insertDataToUser(int current,int limit) {
        this.userService.insertDataToUser();
        IPage<User> user = this.userService.getAllUser(current,limit);
        return new JsonResult(ResultCode.SUCCESS, user);
    }
    /**
    * Description 创建账户的表单
     *
    * @author shao
    * @param :
    * @date 2021/7/9 15:32
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping(value = "/createTableAccount")
    public JsonResult createTableAccount() {
        this.userService.createTableAccount();
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
    * Description添加记录到账户表单
    * @author shao
    * @param current:
    * @param limit:
    * @date 2021/7/9 15:33
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping(value = "/insertDataToAccount")
    public JsonResult insertDataToAccount(int current,int limit) {
        this.userService.insertDataToAccount();
        IPage<Account> account = this.userService.getAllAccount(current,limit);
        return new JsonResult(ResultCode.SUCCESS, account);
    }

    /**
    * Description  获取所有用户信息
    * @author shao
    * @param current:
    * @param limit:
    * @date 2021/7/9 15:34
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping("/getAllUser")
    public JsonResult getAllUser(int current,int limit){
        IPage<User> user = this.userService.getAllUser(current,limit);
        return new JsonResult(ResultCode.SUCCESS, user);

    }
    /**
    * Description 获取所有账户信息
    * @author shao
    * @param current:
    * @param limit:
    * @date 2021/7/9 15:34
    * @return com.zone.demo.util.JsonResult
    */
    @GetMapping("/getAllAccount")
    public JsonResult getAllAccount(int current,int limit){
        IPage<Account> account = this.userService.getAllAccount(current,limit);
        return new JsonResult(ResultCode.SUCCESS, account);

    }

}
